package com.zyf.project.capchain.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.zyf.project.capchain.dto.GoodDTO;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author Zhou Yifan
 */
@Data
public class Good implements Serializable {

    /**
     * 商品主键
     */
    private Long gid;

    /**
     * 商品识别码
     */
    private String idCode;

    /**
     * 商品名字
     */
    private String name;

    /**
     * 商品价格
     */
    private Double price;

    /**
     * 创建时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdTime;

    /**
     * 修改时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime modifiedTime;

    public Good() {
        this.createdTime = LocalDateTime.now();
        this.modifiedTime = LocalDateTime.now();
    }

    public GoodDTO toDTO() {
        GoodDTO goodDTO = new GoodDTO();
        goodDTO.setGid(gid);
        goodDTO.setIdCode(idCode);
        goodDTO.setName(name);
        goodDTO.setPrice(price);
        goodDTO.setCreatedTime(createdTime);
        goodDTO.setModifiedTime(modifiedTime);
        return goodDTO;
    }

}
